from django.db import models
from django.forms import ModelForm, Form, HiddenInput
from django.forms.extras.widgets import SelectDateWidget
from django.contrib import admin
from django.contrib.admin import widgets
from django.contrib.auth.models import User
from django import forms
import datetime

# Create your models here.
class Game(models.Model):
	name = models.CharField(max_length=20)
	game_type = models.CharField(max_length=20)
	objective = models.CharField(max_length=200)
	rules_url = models.URLField(max_length=100)	
	video_url = models.TextField(max_length=700)

	#Identifies Game by Name
	def __unicode__(self):
        	return self.name

class ScheduledGame(models.Model):
	label = models.CharField(max_length=30)
	members = models.ManyToManyField(User, through='Membership')
	unique = models.BigIntegerField(blank=True)
	creator_username = models.BigIntegerField(blank=True)
	game = models.ForeignKey(Game)
	date = models.DateField()
	time = models.CharField(max_length=10)
	city = models.CharField(max_length=30)
	state = models.CharField(max_length=2)
	zipcode = models.CharField(max_length=5)
	player_limit = models.CharField(max_length=10, blank=True)
	private = models.BooleanField(blank=True)
	password = models.CharField(max_length=20, blank=True)
	recurring = models.BooleanField(blank=True)
	recurring_details = models.CharField(max_length=100, blank=True)
	informal_location = models.CharField(max_length=200)
	game_details = models.CharField(max_length=200, blank=True)
	intensity = models.CharField(max_length=30, blank=True)
	
	#Identifies ScheduledGame by details
	def __unicode__(self):
		return str(self.unique)

class Membership(models.Model):
	user = models.ForeignKey(User)
	scheduled_game = models.ForeignKey(ScheduledGame)
	

GAME_TYPES = ( 
	('team sport', 'Team Sport'),
	('individual', 'Individual'),
	('fitness', 'Fitness'),
	('other', 'Other'),
)
class GameForm(ModelForm):

	game_type = forms.ChoiceField(GAME_TYPES)
	class Meta:
		model = Game


TIME_CHOICES = (

                ('00:00', '12:00 am'),('00:30', '12:30 am'),

                ('01:00', '02:00 am'),('01:30', '01:30 am'),

                ('02:00', '02:00 am'),('02:30', '02:30 am'),

                ('03:00', '03:00 am'),('03:30', '03:30 am'),

                ('04:00', '04:00 am'),('04:30', '04:30 am'),

                ('05:00', '05:00 am'),('05:30', '05:30 am'),

                ('06:00', '06:00 am'),('06:30', '06:30 am'),

                ('07:00', '07:00 am'),('07:30', '07:30 am'),

                ('08:00', '08:00 am'),('08:30', '08:30 am'),

                ('09:00', '09:00 am'),('09:30', '09:30 am'),

                ('10:00', '10:00 am'),('10:30', '10:30 am'),

                ('11:00', '11:00 am'),('11:30', '11:30 am'),

                ('12:00', '12:00 pm'),('12:30', '12:30 pm'),

                ('13:00', '01:00 pm'),('13:30', '01:30 pm'),

                ('14:00', '02:00 pm'),('14:30', '02:30 pm'),

                ('15:00', '03:00 pm'),('15:30', '03:30 pm'),

                ('16:00', '04:00 pm'),('16:30', '04:30 pm'),

                ('17:00', '05:00 pm'),('17:30', '05:30 pm'),

                ('18:00', '06:00 pm'),('18:30', '06:30 pm'),

                ('19:00', '07:00 pm'),('19:30', '07:30 pm'),

                ('20:00', '08:00 pm'),('20:30', '08:30 pm'),

                ('21:00', '09:00 pm'),('21:30', '09:30 pm'),

                ('22:00', '10:00 pm'),('22:30', '10:30 pm'),

                ('23:00', '11:00 pm'),('23:30', '11:30 pm'),
)

RECURRING_DETAILS_CHOICES = (
	('daily', 'Daily'),('biweekly', 'Twice a week weekly'),
	('triweekly', 'Three times a week'),('weekly', 'Weekly'),
	('halfmonthly', 'Every two weeks'),('threequartermonthly', 'Every three weeks'),
	('monthly', 'Monthly'),('annually', 'Annually'),
)

STATES = (
	('AL','AL'),
	('AK','AK'),
	('AZ','AZ'),
	('AR','AR'),
	('CA','CA'),
	('CO','CO'),
	('CT','CT'),
	('DE','DE'),
	('FL','FL'),
	('GA','GA'),
	('HI','HI'),
	('ID','ID'),
	('IL','IL'),
	('IN','IN'),
	('IA','IA'),
	('KS','KS'),
	('KY','KY'),
	('LA','LA'),
	('ME','ME'),
	('MD','MD'),
	('MA','MA'),
	('MI','MI'),
	('MN','MN'),
	('MS','MS'),
	('MO','MO'),
	('MT','MT'),
	('NE','NE'),
	('NV','NV'),
	('NH','NH'),
	('NJ','NJ'),
	('NM','NM'),
	('NY','NY'),
	('NC','NC'),
	('ND','ND'),
	('OH','OH'),
	('OK','OK'),
	('OR','OR'),
	('PA','PA'),
	('RI','RI'),
	('SC','SC'),
	('SD','SD'),
	('TN','TN'),
	('TX','TX'),
	('UT','UT'),
	('VT','VT'),
	('VA','VA'),
	('WA','WA'),
	('WV','WV'),
	('WI','WI'),
	('WY','WY'),
)

INTENSITY = (
	('Casual' , 'Casual'),
	('Competitive' , 'Competitive'),
	('Die hard' , 'Die Hard'),
)
class ScheduledGameForm(ModelForm):
	date = forms.DateField(widget=admin.widgets.AdminDateWidget())
	time = forms.ChoiceField(TIME_CHOICES)
	state = forms.ChoiceField(STATES)
	creator_username = forms.IntegerField(initial=0, widget=forms.widgets.HiddenInput(), required=False)
	unique = forms.IntegerField(initial=0, widget=forms.widgets.HiddenInput(), required=False)
	intensity = forms.ChoiceField(INTENSITY)
	members = forms.ModelMultipleChoiceField(queryset=[],widget=forms.widgets.HiddenInput(), required=False)
	recurring_details = forms.ChoiceField(RECURRING_DETAILS_CHOICES)

	class Meta:
		model = ScheduledGame
	#	widgets = {
	#			'date': admin.widgets.AdminDateWidget(),
	#			}

class SearchForm(forms.Form):
	game = forms.ModelChoiceField(Game.objects.all())
	city = forms.CharField(max_length=20)
	state = forms.ChoiceField(STATES)
	zipcode = forms.CharField(max_length=5)

class PasswordForm(forms.Form):
	passwd = forms.CharField(max_length=20)
